//
//  BaseNavViewController.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/11/27.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "BaseNavViewController.h"

@implementation BaseNavViewController

- (void)viewDidLoad{
    
    [super viewDidLoad];
    UIGestureRecognizer *gesture = self.interactivePopGestureRecognizer;
    gesture.enabled = NO;
    UIView *gestureView = gesture.view;
    
    UIPanGestureRecognizer *popRecognizer = [[UIPanGestureRecognizer alloc] init];
    popRecognizer.delegate = self;
    popRecognizer.maximumNumberOfTouches = 1;
    [gestureView addGestureRecognizer:popRecognizer];
    
    //#if USE_方案一
    _navT = [[NavigationInteractiveTransition alloc] initWithViewController:self];
    [popRecognizer addTarget:_navT action:@selector(handleControllerPop:)];
    self.interactivePopGestureRecognizer.delegate = self;
    
}

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    NSUInteger count = self.childViewControllers.count;
    if (count != 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        UIButton *btn = [[UIButton_Extesion alloc]initWithTitle:@"返回" titleColor:[UIColor orangeColor] backImageName:nil imageName:nil fontSize:16];
        [btn sizeToFit];
        [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    }
    [super pushViewController:viewController animated:YES];
}

- (void)back{
    [self popViewControllerAnimated:YES];
}

//实现代理方法
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;{
    NSLog(@"返回了,格格");
    return self.viewControllers.count != 1 && ![[self valueForKey:@"_isTransitioning"] boolValue];

}
@end
